package com.cy.pj.goods.controller;


import com.cy.pj.goods.pojo.Goods;
import com.cy.pj.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/goods/")
public class GoodsController {

    @Autowired//has a
    private GoodsService goodsService;

    @RequestMapping("doFindById/{id}")
    public Goods doFindById(@PathVariable("id") Integer id){
        return goodsService.findById(id);
    }

    @RequestMapping("doUpdateGoods")
    public String doUpdateGoods(@RequestBody Goods entity){
        goodsService.updateGoods(entity);
        return "update ok";
    }
    @RequestMapping("doSaveGoods")
    public String doSaveGoods(@RequestBody Goods entity){
        goodsService.saveGoods(entity);
        return "save ok";
    }

    @RequestMapping("doDeleteById/{id}")
    public String doDeleteById(@PathVariable("id") Integer id){
        goodsService.deleteById(id);
        return "delete ok";
    }

    @RequestMapping("doFindGoods")
    public List<Goods> doFindGoods(){

        return goodsService.findGoods();//viewname
    }

}
